package com.gj.baselib.sysutils;

import android.app.Activity;
import android.content.Context;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager.NameNotFoundException;
import android.view.Window;
import android.view.WindowManager;

public class AndroidAppUtils {

	/**
	 * @Description:获得应用版本号
	 * @param context
	 *            上下文
	 * @return 应用版本号
	 * @throws NameNotFoundException
	 * @exception:
	 */
	public static int getAppVersion(Context context)
			throws NameNotFoundException {
		PackageInfo info = context.getPackageManager().getPackageInfo(
				context.getPackageName(), 0);
		return info.versionCode;
	}

	/**
	 * @Description:获得应用程序可以使用的最大内存(单位：KB)
	 * @return 应用所使用的最大内存
	 * @exception:
	 */
	public static int getApplicationUseMaxMemory() {
		return (int) (Runtime.getRuntime().maxMemory() / 1024);
	}

	/**
	 * @Description:保持屏幕常亮
	 * @param activity
	 * @return void
	 * @exception:
	 */
	public static void keepScreenOn(Activity activity) {
		activity.getWindow().setFlags(
				WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON,
				WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
	}

	/**
	 * @Description:去掉TitleBar
	 * @param activity
	 * @return void
	 * @exception:
	 */
	public static void clearTitle(Activity activity) {
		activity.requestWindowFeature(Window.FEATURE_NO_TITLE);

	}

	/**
	 * @Description:设置全屏
	 * @param activity
	 * @return void
	 * @exception:
	 */
	public static void fullScreen(Activity activity) {
		activity.getWindow().setFlags(
				WindowManager.LayoutParams.FLAG_FULLSCREEN,
				WindowManager.LayoutParams.FLAG_FULLSCREEN);
	}

	/**
	 * @Description:退出应用程序
	 * @return void
	 * @exception:
	 */
	public static void exit() {
		Runtime.getRuntime().exit(0);
	}
}
